var viewer = null;
var owner = null;
var ownerFriends = null;
var ownerFriendsById = {};
var viewerIsOwner = null;
var viewerIsOwnerFriend = null;

var GadGet = new function() {

	this._elem = function(id) {
		return document.getElementById(id);
	};	
	this._setText = function(id, text) {
		document.getElementById(id).innerHTML = text;	
	};
	this._makeDiv = function(id, html) {
		return '<div id='+id+'>'+html+'</div>';
	};
	this._anchor = function(url,label,target) {
		return '<a href='+url+' target='+target+'>'+label+'</a>';
	};
	this._loadOwnerData = function() {
	    alert('carregando');
		var req = opensocial.newDataRequest();
	    req.add(req.newFetchPersonRequest('OWNER'), 'owner');
	    var opt_params = { };
	    opt_params[opensocial.DataRequest.PeopleRequestFields.MAX] = 500;
	    req.add(req.newFetchPeopleRequest('OWNER_FRIENDS', opt_params),'ownerFriends');
	    req.send(handleOwnerData);
	};
	this._handleOwnerData = function(dataResponse) {
	    if (dataResponse.hadError()) {
	      _setText('status', "Error Loading data... Can't tell who owns this page!");
	      return;
	    }
		owner = dataResponse.get("owner").getData();
		ownerFriends = dataResponse.get("ownerFriends").getData().asArray() || [];
	    for (var i=0; i<ownerFriends.length; ++i) {
	      ownerFriendsById[ownerFriends[i].getId()] = ownerFriends[i];
	    }
	    _setText('status', owner.getDisplayName() + "'s Woshambo loaded.  Loading your information...");
	   // var req = opensocial.newDataRequest();
	   // req.add(req.newFetchPersonRequest('VIEWER'), 'viewer');
	   // req.send(handleViewerData);
	};
};